const express = require('express');
const db = require('../utils/db');
const router = express.Router();
const { selectStudentScore } = require("../controller/score")

router.get("/studentScore", (req, res) => {
  const { phone } = req.auth
  // console.log(phone);
  // res.ok(phone)
  const sql = `  
  SELECT ts.className,ts.t_id,s.* FROM t_class AS ts,
    (
      SELECT * FROM t_student WHERE p_phone=?
    ) AS s WHERE s.c_id = ts.id `
  db.query(sql, phone, async (err, results) => {
    if (err) return res.cc(err);
    for (let i in results) {
      const data = await selectStudentScore(results[i].id)
      results[i].score = data
    }
    res.ok(results)
  })
})


module.exports = router